Position actuelle: Accueil> Catégories de fonctions> property_exists

property_exists

Vérifiez si un objet ou une classe a cette propriété
Nom:property_exists
Catégorie:Classes et objets
Langage de programmation:php
Description en une ligne:Vérifie si un objet ou une classe a l'attribut spécifié

Nom de la fonction: propriété_exists ()

Description de la fonction: Property_exists () Fonction vérifie si un objet ou une classe a l'attribut spécifié.

paramètre:

  • $ Classe: requis. Le nom de classe ou l'objet à vérifier.
  • $ Propriété: requise. Le nom d'attribut à vérifier.

Valeur de retour:

  • Renvoie True si la propriété existe et est accessible.
  • Si la propriété n'existe pas ou n'est pas inaccessible, FALS est renvoyé.

Version applicable: PHP 4, PHP 5, PHP 7

Exemple d'utilisation:

  1. Vérifiez si la classe a l'attribut spécifié:
 class MyClass { public $name = "John"; private $age = 25; } $object = new MyClass(); if (property_exists($object, 'name')) { echo "The 'name' property exists."; } else { echo "The 'name' property does not exist."; } // 输出:The 'name' property exists.
  1. Vérifiez si l'objet a l'attribut spécifié:
 class MyClass { public $name = "John"; private $age = 25; } $object = new MyClass(); if (property_exists($object, 'age')) { echo "The 'age' property exists."; } else { echo "The 'age' property does not exist."; } // 输出:The 'age' property does not exist.
  1. Vérifiez si le nom de classe a l'attribut statique spécifié:
 class MyClass { public static $name = "John"; private static $age = 25; } if (property_exists('MyClass', 'name')) { echo "The 'name' static property exists."; } else { echo "The 'name' static property does not exist."; } // 输出:The 'name' static property exists.
  1. Vérifiez si le nom de classe a l'attribut privé statique spécifié:
 class MyClass { public static $name = "John"; private static $age = 25; } if (property_exists('MyClass', 'age')) { echo "The 'age' static property exists."; } else { echo "The 'age' static property does not exist."; } // 输出:The 'age' static property does not exist.
Fonctions similaires
Articles populaires